import {mapGetters} from 'vuex'
export default{
  computed:{
    ...mapGetters('shopCar', ['total']),
  },
  onShow(){
    this.setBadge()
  },
  watch:{
    total(){
      this.setBadge()
    }
  },
  methods:{
    //設置Tabbar的購物車图标也有數字顯示物品數量
    setBadge(){
      if(this.total == 0){
        uni.hideTabBarRedDot()
      }else{ 
        uni.setTabBarBadge({
          index: 2,
          text: this.total + ''//只能是字符串
        })
      }
    }
  }
}